﻿Public Class TMyTriggers
    Inherits TCustomMyObjects

    Friend Sub New(ByVal AOwner As TMyDatabase)
        MyBase.New(AOwner)
    End Sub

    Public Overrides Sub Refresh()
        Dim item As TMyTrigger
        _List.Clear()
        MyQuery.Clear()
        MyQuery.SQL.AppendLine("SELECT")
        MyQuery.SQL.AppendLine(" TRIGGER_CATALOG")
        MyQuery.SQL.AppendLine(",TRIGGER_SCHEMA")
        MyQuery.SQL.AppendLine(",TRIGGER_NAME")
        MyQuery.SQL.AppendLine(",EVENT_MANIPULATION")
        MyQuery.SQL.AppendLine(",EVENT_OBJECT_CATALOG")
        MyQuery.SQL.AppendLine(",EVENT_OBJECT_SCHEMA")
        MyQuery.SQL.AppendLine(",EVENT_OBJECT_TABLE")
        MyQuery.SQL.AppendLine(",ACTION_ORDER")
        MyQuery.SQL.AppendLine(",ACTION_CONDITION")
        MyQuery.SQL.AppendLine(",ACTION_STATEMENT")
        MyQuery.SQL.AppendLine(",ACTION_ORIENTATION")
        MyQuery.SQL.AppendLine(",ACTION_TIMING")
        MyQuery.SQL.AppendLine(",ACTION_REFERENCE_OLD_TABLE")
        MyQuery.SQL.AppendLine(",ACTION_REFERENCE_NEW_TABLE")
        MyQuery.SQL.AppendLine(",ACTION_REFERENCE_OLD_ROW")
        MyQuery.SQL.AppendLine(",ACTION_REFERENCE_NEW_ROW")
        MyQuery.SQL.AppendLine(",CREATED")
        MyQuery.SQL.AppendLine(",SQL_MODE")
        MyQuery.SQL.AppendLine(",DEFINER")
        MyQuery.SQL.AppendLine(",CHARACTER_SET_CLIENT")
        MyQuery.SQL.AppendLine(",COLLATION_CONNECTION")
        MyQuery.SQL.AppendLine(",DATABASE_COLLATION")
        MyQuery.SQL.AppendLine("FROM")
        MyQuery.SQL.AppendLine(" information_schema.triggers")
        MyQuery.SQL.AppendLine("where")
        MyQuery.SQL.AppendLine("trigger_schema=?trigger_schema")
        MyQuery.SQL.AppendLine("ORDER BY")
        MyQuery.SQL.AppendLine(" TRIGGER_NAME")
        MyQuery.DeclareAndSet("trigger_schema", Me.DatabaseName)
        MyQuery.Execute()
        While Not MyQuery.Eof
            item = New TMyTrigger(Me, MyQuery.FieldAsString("TRIGGER_NAME"))
            item._TriggerCatalog = MyQuery.FieldAsString("trigger_catalog")
            item._TriggerSchema = MyQuery.FieldAsString("trigger_schema")
            item._TriggerName = MyQuery.FieldAsString("trigger_name")
            item._EventManipulation = MyQuery.FieldAsString("event_manipulation")
            item._EventObjectCatalog = MyQuery.FieldAsString("event_object_catalog")
            item._EventObjectSchema = MyQuery.FieldAsString("event_object_schema")
            item._EventObjectTable = MyQuery.FieldAsString("event_object_table")
            item._ActionOrder = MyQuery.FieldAsInteger("action_order")
            item._ActionCondition = MyQuery.FieldAsString("action_condition")
            item._ActionStatement = MyQuery.FieldAsString("action_statement")
            item._ActionOrientation = MyQuery.FieldAsString("action_orientation")
            item._ActionTiming = MyQuery.FieldAsString("action_timing")
            item._ActionReferenceOldTable = MyQuery.FieldAsString("action_reference_old_table")
            item._ActionReferenceNewTable = MyQuery.FieldAsString("action_reference_new_table")
            item._ActionReferenceOldRow = MyQuery.FieldAsString("action_reference_old_row")
            item._ActionReferenceNewRow = MyQuery.FieldAsString("action_reference_new_row")
            item._Created = MyQuery.FieldAsDateTime("created")
            item._SqlMode = MyQuery.FieldAsString("sql_mode")
            item._Definer = MyQuery.FieldAsString("definer")
            item._CharacterSetClient = MyQuery.FieldAsString("character_set_client")
            item._CollationConnection = MyQuery.FieldAsString("collation_connection")
            item._DatabaseCollation = MyQuery.FieldAsString("database_collation")
            _List.Add(item)
            MyQuery.MoveNext()
        End While
        MyQuery.Close()
    End Sub


End Class
